package com.novelastudios.data
{
	/**
	 * This is intended to be a base class
	 *  
	 * @author JohnBailey ©2009
	 */
	public class ValuesProxy
	{
		protected var _data:Object;
		
		public function ValuesProxy()
		{
			init();
			setDefaultReturns();
		}
		
		///////////////////////////////////////////////////////////////////////////////
		//								PUBLIC METHODS
		///////////////////////////////////////////////////////////////////////////////
		/**
		 * 
		 * @param key
		 * @param defaultReturn If the key is not found, then this will be returned. 
		 * 		You can set default return values by overridding setDefaultReturns and
		 * 		setting the value for a specific key. 
		 * @return 
		 * 
		 */		
		public function getValue(key:String,defaultReturn:String=""):String
		{
			return hasValue(key) ? _data[key] : defaultReturn;
		}
		
		public function hasValue(key:String):Boolean
		{
			return (_data && _data.hasOwnProperty(key));
		}
		
		/**
		 * 
		 * @param key
		 * @param value
		 * @param force If the key is already existing, this allows the value to overwritten
		 * 
		 */		
		public function setValue(key:String,value:String,force:Boolean=true):void
		{
			if(hasValue(key) && !force) return;
			
			_data[key] = value;
		}
		
		///////////////////////////////////////////////////////////////////////////////
		//								PROTECTED METHODS
		///////////////////////////////////////////////////////////////////////////////
		protected function init():void
		{
			_data = {};
		}
		
		protected function setDefaultReturns():void
		{
			
		}
	}
}